
'''计算一下循环次数'''
def shell_sort_num(arr):
    le = len(arr)
    d = int(le / 2)
    num = 1
    print(f"shell_sort 初始arr==>{arr}")
    while d :
        for i in range(0,d):
            for j in range(i+d, le, d):
                flag = True
                if arr[j] < arr[j - d]:
                    flag = False
                    insert_num = arr[j]
                    for k in range(j -d, -1, -d):
                       if arr[k] > insert_num:
                           num += 1
                           arr[k + d] = arr[k]
                           if k - d < 0:
                               arr[k] = insert_num
                       else:
                           num += 1
                           arr[k + d] = insert_num
                           break

                if flag:
                    num += 1
        d = int(d / 2)

    print(num)
    print(arr)
    return arr

'''计算一下循环次数'''
def insert_sort_num(arr):
    print(f'insert_sort初始arr{arr}')
    num = 1
    for i in range(1, len(arr)):
        flag = True
        if arr[i] < arr[i-1]:
            flag = False
            insert_num = arr[i]
            for j in range(i-1, -1, -1):
                if arr[j] > insert_num:
                    num += 1
                    arr[j + 1] = arr[j]
                    if j - 1 < 0:
                        arr[j] = insert_num
                else:
                    num += 1
                    arr[j + 1] = insert_num
                    break
            print(f'插入排序{arr}')

        if flag:
            num += 1
    print(num)
    print(arr)
    return arr

arr1 = [81, 94, 11, 96, 12, 35, 17, 95, 28, 58, 41, 75, 15]
arr2 = [81, 94, 11, 96, 12, 35, 17, 95, 28, 58, 41, 75, 15]
# 45
shell_sort_num(arr1)
insert_sort_num(arr2)

